/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chelydra.sharelydra.client.message;

/**
 *
 * @author Benjamin
 */
public class UploadPart extends Message {

    int fileId;
    //Status of the file: 0=NOK, 1=OK
    int status;
    int checksum;
    String fileData;

    public UploadPart() {
        
    }


    public UploadPart(int fileId, int status, int checksum, String fileData){
        super(4,fileId+"-"+status+"-"+checksum+"-"+fileData);
        this.fileId = fileId;
        //if status = ok = 1, error = 0
        this.status = status;
        this.checksum = checksum;
        this.fileData = fileData;
    }

    public String toString(){
        String result;
        this.data = this.fileId+"-"+this.status+"-"+this.checksum+"-"+this.fileData;
        result = super.toString();
        return result;
    }

    public void fromString(String strIn){
        super.fromString(strIn);
        String str=this.data;
        int firstMinusPos = str.indexOf("-");
        int secondMinusPos = str.indexOf("-",firstMinusPos+1);
        int thirdMinusPos = str.indexOf("-",secondMinusPos+1);
        this.fileId=Integer.parseInt(str.substring(0,firstMinusPos));
        this.status=Integer.parseInt(str.substring(firstMinusPos+1,secondMinusPos));
        this.checksum=Integer.parseInt(str.substring(secondMinusPos+1,thirdMinusPos));
        this.fileData=str.substring(thirdMinusPos+1);
    }

    public int getChecksum() {
        return checksum;
    }

    public void setChecksum(int checksum) {
        this.checksum = checksum;
    }

    public String getFileData() {
        return fileData;
    }

    public void setFileData(String fileData) {
        this.fileData = fileData;
    }

    public int getFileId() {
        return fileId;
    }

    public void setFileId(int fileId) {
        this.fileId = fileId;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }



}
